package com.sgb.packers.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.sgb.packers.api.PackersNet;
import com.sgb.packers.entity.ContractLaborEntity;
import com.sgb.packers.entity.WorkRecordsEntity;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.common.base.BaseViewModel;
import com.swgk.core.util.MLog;

import org.jetbrains.annotations.NotNull;

/**
 * @author: 王彬臣
 * @date: 2021/11/24
 * @Description:
 */
public class WorkOrContractorDetailModel extends BaseViewModel {
    public MutableLiveData<WorkRecordsEntity> ldRecords = new MutableLiveData<>();
    public MutableLiveData<ContractLaborEntity> contractLaborEntity = new MutableLiveData<>();
    public MutableLiveData<Boolean> serviceError = new MutableLiveData<>();

    public WorkOrContractorDetailModel(@NonNull @NotNull Application application) {
        super(application);
    }

    public void getPointWork(String no) {
        mLoading.postValue(SHOW_LODING);
        PackersNet.getInstance().getService().pointWorkDetail(no, "1").enqueue(new ICallBack<BaseEntity<WorkRecordsEntity>>() {
            @Override
            public void onSuccess(BaseEntity<WorkRecordsEntity> data) {
                if (data == null || data.getData() == null) {
                    serviceError.postValue(true);
                    return;
                }
                ldRecords.postValue(data.getData());
            }
        });
    }

    public void getWrapWork(String no) {
        mLoading.postValue(SHOW_LODING);
        PackersNet.getInstance().getService().wrapWorkDetail(no, "1").enqueue(new ICallBack<BaseEntity<ContractLaborEntity>>() {
            @Override
            public void onSuccess(BaseEntity<ContractLaborEntity> data) {
                if (data == null || data.getData() == null) {
                    serviceError.postValue(true);
                    return;
                }
                contractLaborEntity.postValue(data.getData());
            }
        });
    }
}
